
$(function () {
	
	
	//1.自动播放
	var currentIndex = 0;
	var totalPic = $('.banner_img_a').length;
	
	//封装一个方法,该方法 根据 当前 的索引,设置轮播图的切换
	function showCurrentImg () {
		$('.banner_img_a').eq(currentIndex).show()
		.siblings('.banner_img_a').hide();
		
		$('.indicator span').eq(currentIndex).addClass('cur')
		.siblings().removeClass('cur');
	}
	
	var showNextImg = function () {
		currentIndex = currentIndex >= totalPic - 1 ? 0 : currentIndex + 1;
		
		showCurrentImg()
	}
	var timer = setInterval(showNextImg,3000);
	
	//手动轮播
	$('.indicator span').hover(function () {
		//鼠标悬停时
		//关闭定时器
		clearInterval(timer)
		
		//获取鼠标所在 li的索引值
		currentIndex = $(this).index()
		//设置轮播效果
		showCurrentImg();
		
	},function () {
		//鼠标离开时
		timer = setInterval(showNextImg, 3000)
		
	})
	
	//鼠标悬停/离开 next/prev 时,关闭/开启定时器
	$('.page span').hover(function () {
		clearInterval(timer);
	},function () {
		timer = setInterval(showNextImg, 1000);
	})
	
	//点击next
	$('.page .next').click(function () {
		showNextImg();
	})
	
	//点击prve
	$('.page .prev').click(function () {
		currentIndex = currentIndex <= 0 ? totalPic - 1 : currentIndex - 1;
		showCurrentImg();
	})
	
	
	
	
	
	
})


